# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=language-haskell-extract
pkgname=haskell-language-haskell-extract
pkgver=0.2.4
pkgrel=15
pkgdesc="Module to automatically extract functions from the local code"
url="https://github.com/finnsson/language-haskell-extract"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-regex-posix')
makedepends=('ghc')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz
        ghc-8.10.patch)
sha512sums=('6408459abf9d531ccbe7d65766d38fcb93f4d3f9c77db1a706231bf6d8ad6f845fcefc4fbb03833f45c74f21f324a44760f3c89ff093c69f1f9999e64344ab4d'
            '2992e1e0ca320b4689388e8ff0588611de0ae54ea1c0dde537cda708957e95f2c03f56d818862470ca354d321f032867546cf2c1c72bfeec148fe71befcd9e32')

prepare() {
    cd $_hkgname-$pkgver
    patch -p1 -i ../ghc-8.10.patch
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 "BSD3.txt" "${pkgdir}/usr/share/licenses/${pkgname}/BSD3.txt"
    rm -f "${pkgdir}/usr/share/doc/${pkgname}/BSD3.txt"
}
